<?php use_helper('I18N'); ?>
<style type="text/css">
    p img {
        background: none repeat scroll 0 0 white;
        border: 1px solid #BBBBBB;
        margin: 7px 14px 7px 0;
        padding: 5px;
        height: 50px;
        /*width: 160px;*/
    }
</style>
<script type="text/javascript">
    $(function() {
        $("#changeAccountInformation").button({
            icons: {
                primary: "ui-icon-note"
            }
        }).click(function(){
            $("#frmMyAccount").attr("action", "/member/accountEdit");
            $("#frmMyAccount").submit();
        });
        $("#changeAddressbook").button({
            icons: {
                primary: "ui-icon-mail-closed"
            }
        }).click(function(){
            $("#frmMyAccount").attr("action", "/member/addressBook");
            $("#frmMyAccount").submit();
        });
        $("#changeAccountPassword").button({
            icons: {
                primary: "ui-icon-key"
            }
        }).click(function(){
            $("#frmMyAccount").attr("action", "/member/changePassword");
            $("#frmMyAccount").submit();
        });
    });
</script>
<div id="content">

    <!-- ========== CATEGORIES TABS ========= -->
    <!-- ==================================== -->
    <table id="contentMainWrapper" border="0" cellpadding="0" cellspacing="0" width="100%">
        <tbody>
        <tr>
            <td id="column-left" style="width: 215px;">
                <div style="width:215px;">
                    <!--// bof: categories //-->
                    <div class="box" id="categories" style="width:215px;">
                        <div class="box-border">
                            <div class="box-head">
                                <?php echo __('Categories') ?>
                            </div>
                            <div class="box-body">
                                <?php include_component('component', 'categoriesSideMenu') ?>
                            </div>
                        </div>
                    </div>
                    <!--// eof: categories //-->
                    <!--// bof: specials //-->
                    <div class="box" id="specials" style="width:215px;">
                        <div class="box-border">
                            <div class="box-head">
                                <a href="<?php echo url_for("/product/specialItem") ?>"><?php echo __('Specials') ?></a>
                            </div>
                            <div class="box-body">
                                <?php include_component('component', 'specialsSideMenu', array('param' => 'will implement for categoryType')) ?>
                            </div>

                        </div>
                    </div>
                    <!--// eof: specials //-->
                </div>
            </td>
            <td id="column-center" valign="top">
                <div class="column-center-padding">

                    <div class="centerColumn" id="accountDefault">
                        <?php if ($sf_flash->has('errorMsg')): ?>
                            <?php echo $sf_flash->get('errorMsg') ?>
                        <?php endif; ?>
                        <h1 id="accountDefaultHeading">My Account</h1>

                        <div id="accountLinksWrapper" class="back">
                            <form name="frmMyAccount" id="frmMyAccount" action="">
                            <table cellpadding="3" cellspacing="3">
                                <tr>
                                    <td>
                                        <button id="changeAccountInformation" style="width: 330px">View or change my
                                            account information
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <button id="changeAddressbook" style="width: 330px">View or change entries in my
                                            address book
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <button id="changeAccountPassword" style="width: 330px">Change my account
                                            password.
                                        </button>
                                    </td>
                                </tr>
                            </table>
                            </form>
                        </div>

                        <br class="clearBoth">
                        <div class="forward">
                            <a href="<?php echo url_for("/member/myAccount?query=ALL") ?>"
                               style="text-decoration: none">
                                <img title="View" alt="View"
                                     src="/images/buttons/arrow-right.png">&nbsp;<strong><?php echo __('Show All Orders') ?></strong>
                            </a>
                        </div>
                        <br class="clearBoth">
                        <table id="prevOrders" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <caption><h2>Previous Orders</h2></caption>
                            <tbody>
                            <tr class="tableHeading">
                                <th scope="col">Date</th>
                                <th scope="col">No.</th>
                                <th scope="col">Ship To</th>
                                <th scope="col">Status</th>
                                <th scope="col">Total</th>
                                <th scope="col">View</th>
                            </tr>
                            <?php
                            if (count($cmsMemberOrders) > 0) {
                                foreach ($cmsMemberOrders as $cmsMemberOrder): ?>
                            <tr>
                                <td width="70px">
                                    <?php
                                        $timeStamp = strtotime($cmsMemberOrder->getCreatedOn());
                                        $dateString = date(Globals::FULL_DATETIME_FORMAT, $timeStamp);
                                        echo $dateString;
                                    ?>
                                </td>
                                <td width="30px"># <?php echo $cmsMemberOrder->getOrderId() ?></td>
                                <td>
                                    <address>
                                        <?php $address = $cmsMemberOrder->getAddress1();

                                        if ($cmsMemberOrder->getAddress2() != null && $cmsMemberOrder->getAddress2() != "")
                                            $address .= "<br>" . $cmsMemberOrder->getAddress2();

                                        $address2 = "";
                                        if ($cmsMemberOrder->getPostcode() != null && $cmsMemberOrder->getPostcode() != "")
                                            $address2 = $cmsMemberOrder->getPostcode();

                                        if ($cmsMemberOrder->getCity() != null && $cmsMemberOrder->getCity() != "") {
                                            if ($address2 != "")
                                                $address2 .= " ";
                                            $address2 .= $cmsMemberOrder->getCity();
                                        }
                                        if ($cmsMemberOrder->getState() != null && $cmsMemberOrder->getState() != "") {
                                            if ($address2 != "")
                                                $address2 .= "<br>";
                                            $address2 .= $cmsMemberOrder->getState();
                                        }
                                        if ($cmsMemberOrder->getCountry() != null && $cmsMemberOrder->getCountry() != "") {
                                            if ($address2 != "")
                                                $address2 .= " ";
                                            $address2 .= $cmsMemberOrder->getCountry();
                                        }

                                        echo $address."<br>".$address2;
                                        ?>
                                    </address>
                                </td>
                                <td width="70px"><?php echo $cmsMemberOrder->getStatusCode() ?></td>
                                <td align="right" width="70px">RM <?php echo $cmsMemberOrder->getTotalAmount() ?></td>
                                <td align="right">
                                    <a href="<?php echo url_for("/member/viewInvoice?id=" . $cmsMemberOrder->getOrderId()) ?>"
                                       style="text-decoration: none">
                                        <img title="View" alt="View"
                                             src="/images/buttons/arrow-right.png">&nbsp;<strong><?php echo __('View') ?></strong>
                                    </a>
                                </td>
                            </tr>
                            <?php endforeach;
                            } else {
                            ?>
                            <tr>
                                <td colspan="6"><div align="center">No items</div></td>
                            </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                        <br class="clearBoth">

                    </div>

                    <div class="clear"></div>

                </div>
            </td>
        </tr>
        </tbody>
    </table>

</div>